package com.zmm.study.order.config;

import com.zmm.study.order.interceptor.OrderAuthInterceptor;
import com.zmm.util.auth.filter.AnonymousFilter;
import com.zmm.util.auth.registry.ReqParamResolverComposite;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 900045
 * @description:
 * @name OrderAppInterceptorConfig
 * @date By 2021-10-19 19:07:03
 */
@Configuration
public class OrderAppInterceptorConfig implements WebMvcConfigurer {
	
	@Resource
	private OrderAuthInterceptor orderAuthInterceptor;

	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
		WebMvcConfigurer.super.addArgumentResolvers(resolvers);
		resolvers.add(new ReqParamResolverComposite());
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//指定拦截器类//指定该类拦截的url
		orderAuthInterceptor.addPreFilter(new AnonymousFilter());
		registry.addInterceptor(orderAuthInterceptor)
				.addPathPatterns("/**").excludePathPatterns("/static/**");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
		WebMvcConfigurer.super.addResourceHandlers(registry);
	}
}
